wallThickness = 0.5
fudgeFactor = 0.3 --mm
sideLength = 25 
boxheight = 12.5 --mm, front plate is now short.
screwMountHeight = 7.5
legSide = 3.0
legCenterDistance = 6 --distance from leg to center of object
legLength = 50 --actual length of leg, pointless
centerHoleRadius = 4.5
centerTriHoleRadius = 5.75
topBoxCutOutWidth = 10
topBoxCutOutLength = 10
topBoxSpacing = 2 --top cut outs will result in window frame pattern, how thick should window frame be
bottomTriSide1 = 6.4

bottomTriAdjustment = 0.5

bottomTriSide2 = 6.5
bottomTriSide3 = sqrt(bottomTriSide2*bottomTriSide2 + bottomTriSide1*bottomTriSide1)

screwMountHeight = 2.6
screwMountRadius = 2.24
screwDiameter = 1.2
screwSeparation = 20.0 --mm

supportSide = 0.8 --width of support material
supportSeparation = 5.0 --distance between supports
supportDeadZone = 1.0 --distance from center where there should be no support

fn createLeg degrees =
(
		leg = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:legSide height:legSide mapcoords:on pos:[0,-legLength/2-legCenterDistance,wallThickness] isSelected:on 
		leg.pivot = [0,0,0]
		rotate $ (angleaxis degrees [0,0,1])
		ProBoolean.CreateBooleanObject base leg 2 0 1
)

fn createTopBox x y =
(
	insideBoxHeight = wallThickness*2+legSide + ((boxheight-wallThickness*2) - (wallThickness+legSide))
	offSetY = topBoxSpacing/2.0+topBoxCutOutLength/2.0
	offSetX = topBoxSpacing/2.0+topBoxCutOutWidth/2.0
	print offSetX
	print offSetY
	aBox = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:topBoxCutOutLength width:topBoxCutOutWidth height:(boxHeight - insideBoxHeight + wallThickness*2) mapcoords:on pos:[offSetX*x,offSetY*y,(insideBoxHeight - wallThickness)] isSelected:on 
  	ProBoolean.CreateBooleanObject base aBox 2 0 1
)

fn createBottomTri degrees =
(
	triHeight = wallThickness*4+legSide
	tri = Prism side1Segs:1 side2Segs:1 side3Segs:1 heightsegs:1 side1Length:bottomTriSide1 side2Length:bottomTriSide2 side3Length:bottomTriSide3 height:triHeight mapcoords:on pos:[topBoxSpacing/2+centerHoleRadius-bottomTriAdjustment,topBoxSpacing/2,-wallThickness] isSelected:on
	modPanel.addModToSelection (mirror ()) ui:on
	$.modifiers[#Mirror].mirror_axis = 1
	$.modifiers[#Mirror].copy = on
	$.modifiers[#Mirror].offset = -topBoxSpacing
	$.pivot = [0,0,0]
	rotate $ (angleaxis degrees [0,0,1])
	centerTriHole = Cylinder smooth:on heightsegs:5 capsegs:1 sides:18 height:(triHeight*2) radius:centerTriHoleRadius mapcoords:on pos:[0,0,-wallThickness] isSelected:on
	select tri
	ProBoolean.CreateBooleanObject tri centerTriHole 2 0 1
	select base
	ProBoolean.CreateBooleanObject base tri 2 0 1
 )
 
 fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
 
 fn createSideSupport x =
 (
	insideBoxHeight = wallThickness*2+legSide + (((boxheight-wallThickness*2) - (wallThickness+legSide))/2)	 
	centerPos = [(-sideLength/2-wallThickness/2)*x,0,insideBoxHeight-wallThickness/2]
	cornerPos = [(-sideLength/2-wallThickness/2)*x,-sideLength/2,boxHeight]
	degrees = (GetVectorsAngle centerPos cornerPos)/2

	suppportLength = sqrt(sideLength*sideLength + insideBoxHeight*insideBoxHeight)

	sideSupport1  = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:suppportLength width:wallThickness height:wallThickness mapcoords:on pos:centerPos isSelected:on 	
	rotate sideSupport1 (angleaxis degrees [1,0,0])
	sideSupport2  = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:suppportLength width:wallThickness height:wallThickness mapcoords:on pos:centerPos isSelected:on 	
	rotate $ (angleaxis -degrees [1,0,0])		
	ProBoolean.CreateBooleanObject base sideSupport1 0 0 1
	ProBoolean.CreateBooleanObject base sideSupport2 0 0 1
)

fn createScrewMount x y =
(
mount1 = Cylinder smooth:on heightsegs:1 capsegs:1 sides:25 height:(screwMountHeight + wallThickness*0.5) radius:screwMountRadius mapcoords:on pos:[screwSeparation/2*x,screwSeparation/2*y,0] isSelected:on
hole1 = Cylinder smooth:on heightsegs:1 capsegs:1 sides:25 height:(screwMountHeight*2) radius:(screwDiameter/2) mapcoords:on pos:[screwSeparation/2*x,screwSeparation/2*y,0] isSelected:on	
select mount1
ProBoolean.CreateBooleanObject mount1 hole1 2 0 1
ProBoolean.CreateBooleanObject base mount1 0 0 1	
)

fn createSupport x y =
(
	temp = distance [x,y,0] [0,0,0]
	if( temp > supportDeadZone) do
	(
		support = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:0.5 width:supportSide height:(boxHeight + screwMountHeight - wallThickness) mapcoords:on pos:[x,y,0] isSelected:on 
		ProBoolean.CreateBooleanObject base support 0 0 1
	)
)

base  = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:sideLength width:sideLength height:boxheight mapcoords:on pos:[0,0,0] isSelected:on 
inside = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:(sideLength*2) width:(sideLength-wallThickness*2) height:((boxheight-wallThickness*2) - (wallThickness+legSide)) mapcoords:on pos:[0,0,wallThickness*2+legSide] isSelected:on 
inside2 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:(sideLength*2) width:(sideLength-wallThickness*2) height:((boxheight-wallThickness*2) - (wallThickness+legSide)) mapcoords:on pos:[0,0,wallThickness*2+legSide] isSelected:on 
rotate $ (angleaxis 90 [0,0,1])
ProBoolean.CreateBooleanObject base inside 2 0 1
ProBoolean.CreateBooleanObject base inside2 2 0 1
select base
rotate $ (angleaxis 45 [0,0,1])
createLeg(0)
createLeg(90)
createLeg(180)
createLeg(270)

centerHole = Cylinder smooth:on heightsegs:5 capsegs:1 sides:18 height:(legSide + wallThickness*2 + wallThickness) radius:centerHoleRadius mapcoords:on pos:[0,0,-wallThickness] isSelected:on
ProBoolean.CreateBooleanObject base centerHole 2 0 1
rotate base (angleaxis -45 [0,0,1])
createTopBox 1 1
createTopBox -1 1
createTopBox -1 -1
createTopBox 1 -1

createBottomTri 0
createBottomTri 90
createBottomTri 180 
createBottomTri 270

createSideSupport 1
createSideSupport -1

base.pos.Z += screwMountHeight

createScrewMount 1 1
createScrewMount -1 1
createScrewMount -1 -1
createScrewMount 1 -1

endPoint = sideLength/2 - wallThickness

/*for i = 0  to endPoint by supportSeparation  do
(
	createSupport 0 i
	createSupport 0 -i
	createSupport i 0
	createSupport -i 0	
)

supportDeadZone = -1 --set deadZone to negative number so we can add center support, since createsupport 
								--checks distance to be greater than this number
createSupport 0 0
*/